#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>


#define PLUGIN_VERSION "1.0"

int  g_TeganDmgEnable;
ConVar hCvar_TeganDmgEnable;


public Plugin:myinfo =
{
	name = "L4D2_Infected_damage_kill",
	author = "ヾ藤野深月ゞ",
	description = "所有特感攻击秒杀幸存者",
	version = PLUGIN_VERSION,
	url = "https://gitee.com/sweet-and-sour-bombs"
}

public OnPluginStart()
{
	RegAdminCmd("sm_miaosha", Command_TeganSwitch, ADMFLAG_KICK, "特感秒杀指令开关");
	hCvar_TeganDmgEnable = CreateConVar("tank_tegandamage_enable", "1", "是否启用特感秒杀插件", FCVAR_NOTIFY, true, 0.0, true, 1.0);


	HookConVarChange(hCvar_TeganDmgEnable, eConvarChanged);
	HookEvent("player_hurt",			Event_PlayerHurt, EventHookMode_Pre);
	HookEvent("player_incapacitated",			Event_PlayerIncapacitated, EventHookMode_Pre);  //玩家倒地事件	

}

public void OnMapStart()
{
	CvarsChanged();
}

public void eConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
{
	CvarsChanged();
}

void CvarsChanged()
{
	g_TeganDmgEnable = hCvar_TeganDmgEnable.IntValue;

}

public Action Command_TeganSwitch(int client, int args)
{
	if (g_TeganDmgEnable)
	{
		hCvar_TeganDmgEnable.IntValue = 0;
		PrintToChat(client, "\x04[提示]\x05特感秒杀插件已\x03关闭\x05.");
	}
	else
	{
		hCvar_TeganDmgEnable.IntValue = 1;
		PrintToChat(client, "\x04[提示]\x05特感秒杀插件已\x03开启\x05.");
	}
	return Plugin_Handled;
}

/* 玩家受伤 */
public Action:Event_PlayerHurt(Handle:event, String:event_name[], bool:dontBroadcast)
{
	
	if(g_TeganDmgEnable == 0)
	return Plugin_Continue;
	
	new victim = GetClientOfUserId(GetEventInt(event, "userid"));
	new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	new String:WeaponUsed[256];
	GetEventString(event, "weapon", WeaponUsed, sizeof(WeaponUsed));
	//if(IsValidPlayer(victim) && GetClientTeam(victim) == 2 && !IsFakeClient(victim))
	if(IsValidPlayer(victim) && IsValidPlayer(attacker) && GetClientTeam(victim) == 2)
	{
		if(StrEqual(WeaponUsed, "boomer_claw"))   //boomer
		{
			PrintToChatAll("\x04[提示]\x03Boomer%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "tank_claw") || StrEqual(WeaponUsed, "tank_rock"))  //tank
		{
			PrintToChatAll("\x04[提示]\x03Tank%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "spitter_claw") || StrEqual(WeaponUsed, "insect_swarm"))  //spitter
		{
			PrintToChatAll("\x04[提示]\x03Spitter%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "hunter_claw"))  //hunter
		{
			PrintToChatAll("\x04[提示]\x03Hunter%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "smoker_claw"))  //smoker
		{
			PrintToChatAll("\x04[提示]\x03Smoker%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "charger_claw"))  //charger
		{
			PrintToChatAll("\x04[提示]\x03Charger%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "jockey_claw"))  //jockey
		{
			PrintToChatAll("\x04[提示]\x03Jockey%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}					
	}
	return Plugin_Handled;
}


/* 玩家倒地 */
public Action:Event_PlayerIncapacitated(Handle:event, String:event_name[], bool:dontBroadcast)
{
	
	if(g_TeganDmgEnable == 0)
	return Plugin_Continue;
	
	new victim = GetClientOfUserId(GetEventInt(event, "userid"));
	new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	new String:WeaponUsed[256];
	GetEventString(event, "weapon", WeaponUsed, sizeof(WeaponUsed));
	//if(IsValidPlayer(victim) && GetClientTeam(victim) == 2 && !IsFakeClient(victim))
	if(IsValidPlayer(victim) && IsValidPlayer(attacker) && GetClientTeam(victim) == 2)
	{
		if(StrEqual(WeaponUsed, "boomer_claw"))   //boomer
		{
			PrintToChatAll("\x04[提示]\x03Boomer%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "tank_claw") || StrEqual(WeaponUsed, "tank_rock"))  //tank
		{
			PrintToChatAll("\x04[提示]\x03Tank%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "spitter_claw") || StrEqual(WeaponUsed, "insect_swarm"))  //spitter
		{
			PrintToChatAll("\x04[提示]\x03Spitter%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "hunter_claw"))  //hunter
		{
			PrintToChatAll("\x04[提示]\x03Hunter%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "smoker_claw"))  //smoker
		{
			PrintToChatAll("\x04[提示]\x03Smoker%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "charger_claw"))  //charger
		{
			PrintToChatAll("\x04[提示]\x03Charger%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}
		else
		if(StrEqual(WeaponUsed, "jockey_claw"))  //jockey
		{
			PrintToChatAll("\x04[提示]\x03Jockey%s\x05杀死了\x03%s\x05.", GetPlayerName(attacker, true), GetTrueName(victim));
			ForcePlayerSuicide(victim);
		}					
	}
	return Plugin_Handled;
}

stock bool:IsValidPlayer(Client)
{
	//if (Client < 1 || Client > MaxClients) return false;
	//if (!IsClientConnected(Client) || !IsClientInGame(Client)) return false;
	return true;
}


char[] GetTrueName(int client)
{
	char sName[32];
	int Bot = IsClientIdle(client);

	if(Bot != 0)
		FormatEx(sName, sizeof(sName), "闲置:%N", Bot);
	else
		GetClientName(client, sName, sizeof(sName));
	return sName;
}

int IsClientIdle(int client) 
{
	if (!HasEntProp(client, Prop_Send, "m_humanSpectatorUserID"))
		return 0;

	return GetClientOfUserId(GetEntProp(client, Prop_Send, "m_humanSpectatorUserID"));
}


char[] GetPlayerName(int client, bool bPromptType)
{
	char sName[32];
	if (!IsFakeClient(client) && IsPlayerAlive(client) && GetClientTeam(client) == 3 && GetEntProp(client, Prop_Send, "m_zombieClass"))
		FormatEx(sName, sizeof(sName), "%s%N", !bPromptType ? "" : "\x04", client);
	else
	{
		GetClientName(client, sName, sizeof(sName));
		SplitString(sName, "", sName, sizeof(sName));
	}
	return sName;
}









